package mvc1;

import java.util.Date;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import util.DateUtil;

@Controller
public class UserDataController {

    @RequestMapping(value="/userData/input.do" , method = RequestMethod.GET)
    public String input(Model model) {
        model.addAttribute("currentTime", DateUtil.toYMDHMS(new Date()));
        return "userDataInput";
    }

    @RequestMapping(value="/userData/input.do", method = RequestMethod.POST)
    public String input(UserData userData, Model model) {
        model.addAttribute("currentTime", DateUtil.toYMDHMS(new Date()));
if (userData.getName() == null || userData.getName().isEmpty()) {
            // 입력 데이터 오류이므로, 재입력 요구
            model.addAttribute("errorMessage", "이름을 입력해야합니다.");
            return "userDataInput";
        }
        return "userDataInputSuccess";
    }

}
